//
//  HHCustomSideslipViewController.m
//  Flower
//
//  Created by 花花 on 2016/12/12.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "HHCustomSideslipViewController.h"
#import "HHSideslipCell.h"
@interface HHCustomSideslipViewController ()<UITableViewDelegate, UITableViewDataSource, HHSideslipCellDelegate>
@property (strong, nonatomic) UITableView *tableView;
@end

@implementation HHCustomSideslipViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 15;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *const kCellId = @"kCellId";
    
    
    HHSideslipCell *cell =[tableView dequeueReusableCellWithIdentifier:kCellId];
    if (cell == nil) {
        // 当然可以直接继承ZJSwipeTableViewCell进行自定义cell, 也支持xib
        // 对cell进行相同的设置
        cell = [[HHSideslipCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellId];
        cell.delegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    // 对cell进行个性化的设置 注意cell重用的问题 -- 数据填充等
    
    // 可以为每个cell设置不同的动画类型, 目前支持常用的四种
    // 当然设置的时候需要注意cell重用的问题, 应该为所有的cell都明确设置style
    /**
     * 例如当只想为第一个cell设置style为ZJsideslipViewAnimatedStyleOverlap 其他设置为默认的
     * 一定不能少了 else 语句, 否则是会出现重用出错的问题, 不清楚的可以自行查阅cell重用内容显示不对的解决方法
     if (indexPath.row==0) {
     cell.sideslipViewAnimatedStyle = ZJsideslipViewAnimatedStyleOverlap;
     }
     else {
     cell.sideslipViewAnimatedStyle = ZJsideslipViewAnimatedStyleDefault;
     
     }
     */
    if (indexPath.row%4==0) {
        cell.sideslipViewAnimatedStyle = HHSideslipViewAnimatedStyleParallax;
    }
    else if (indexPath.row%4==1) {
        cell.sideslipViewAnimatedStyle = HHSideslipViewAnimatedStyleDefault;
        
    }
    else if (indexPath.row%4==2) {
        cell.sideslipViewAnimatedStyle = HHSideslipViewAnimatedStyleNone;
        
    }
    else {
        cell.sideslipViewAnimatedStyle = HHSideslipViewAnimatedStyleParallax;
        
    }
    cell.textLabel.text = [NSString stringWithFormat:@"当前页是:----%zd", (long)indexPath.row];
    
    cell.backgroundColor = [UIColor whiteColor];
//    cell.closeOtherCellSwipeViewWhenOpenSwipeView = NO;
    cell.threholdPercent = 0.9;
    cell.threholdSpeed = 400;
    cell.overlayerBackgroundColor =[UIColor orangeColor];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (NSArray<HHSideslipButton *> *)tableView:(UITableView *)tableView leftButtonsAtIndexPath:(NSIndexPath *)indexPath {
    HHSideslipButton *leftBtn = [[HHSideslipButton alloc] initWithTitle:@"小房子" image:nil onClickHandler:^(UIButton *swipeButton) {
        
     [self showHudAutoHideString:[NSString stringWithFormat:@"点击了小房子--%zd", (long)indexPath.row]];
    }];
    HHSideslipButton *leftBtn1 = [[HHSideslipButton alloc] initWithTitle:@"消息" image:nil onClickHandler:^(UIButton *swipeButton) {
        
[self showHudAutoHideString:[NSString stringWithFormat:@"点击了消息--%zd", indexPath.row]];
        
    }];
    
    HHSideslipButton *leftBtn2 = [[HHSideslipButton alloc] initWithTitle:@"等等" image:nil onClickHandler:^(UIButton *swipeButton) {
           [self showHudAutoHideString:[NSString stringWithFormat:@"点击了等等--%zd", indexPath.row]];
  
    }];
    HHSideslipButton *leftBtn3 = [[HHSideslipButton alloc] initWithTitle:@"笑脸" image:[UIImage imageNamed:@"selected-4"] onClickHandler:^(UIButton *swipeButton) {
        

           [self showHudAutoHideString:[NSString stringWithFormat:@"点击了笑脸--%zd", (long)indexPath.row]];
    }];
    return @[leftBtn,leftBtn1, leftBtn2,leftBtn3];
}

- (NSArray<HHSideslipButton *> *)tableView:(UITableView *)tableView rightButtonsAtIndexPath:(NSIndexPath *)indexPath {
    
    HHSideslipButton *leftBtn = [[HHSideslipButton alloc] initWithTitle:@"小房子" image:[UIImage imageNamed:@"selected-1"] onClickHandler:^(UIButton *swipeButton) {
        [self showHudAutoHideString:[NSString stringWithFormat:@"点击了小房子--%zd", indexPath.row]];

    }];
    
    HHSideslipButton *leftBtn1 = [[HHSideslipButton alloc] initWithTitle:@"消息" image:[UIImage imageNamed:@"selected-2"] onClickHandler:^(UIButton *swipeButton) {
[self showHudAutoHideString:[NSString stringWithFormat:@"点击了消息--%zd", (long)indexPath.row]];
    }];
    
    HHSideslipButton *leftBtn2 = [[HHSideslipButton alloc] initWithTitle:@"等等" image:[UIImage imageNamed:@"selected-3"] onClickHandler:^(UIButton *swipeButton) {
        [self showHudAutoHideString:[NSString stringWithFormat:@"点击了等等--%zd", (long)indexPath.row]];
 
        
    }];
    HHSideslipButton *leftBtn3 = [[HHSideslipButton alloc] initWithTitle:@"笑脸" image:[UIImage imageNamed:@"selected-4"] onClickHandler:^(UIButton *swipeButton) {
        
        [self showHudAutoHideString:[NSString stringWithFormat:@"点击了笑脸--%zd", indexPath.row]];

        
    }];
    
    return @[leftBtn,leftBtn1, leftBtn2,leftBtn3];
}


- (UITableView *)tableView {
    if (!_tableView) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screen_width, screen_height-64) style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        // 行高度
        tableView.rowHeight = 100;
        _tableView = tableView;
    }
    return _tableView;
}
@end
